---
--类名: DesktopController.lua
--创建日期: 2015-4-3
--创建人: 陈小虎
--功能描述: 世界桌面控制器
--修改内容：
--修改日期:
--修改人:
--修改备注:
--
local Desktop = import("..views.Desktop")
local EscortWarning = import("..views.EscortWarning")
local EscortFinish = import("..views.EscortFinish")
local MapSiteView = import("..views.MapSiteView")

local TeamModel = app:getInst("TeamModel")

local TaskTrackController = import("...tasktrack.controllers.TaskTrackController")

local DesktopController = class("DesktopController",function()
    return display.newNode()
end)

function DesktopController:ctor(model)
    cc(self):addComponent("components.behavior.EventProtocol"):exportMethods()

    self.mDesktopModel = model
    self.mDesktop = Desktop.new(self.mDesktopModel)
    self:addChild(self.mDesktop)

    self.mDesktop:setBottomAcionOverCB(function()
            self:checkGuide()
        end)
    self.mDesktop:setTopSwitchOverCB(function()
            self:checkGuide()
        end)

    -- TODO 暂时按UD是否初始化来何时刷新desktop，有时间优化一下desktop
    if UD:isInit() then
        self:initData()
    end

    self:enableNodeEvents()
end

function DesktopController:initData()
    self.mDesktopModel:initFuncConf()
    self.mDesktop:initData()

   self:showTaskTrack()

   self:refreshPreviewFunc()
   self:initFunctionByIds()

   self:addOrDelWorldLock()
   self:refreshRewardBtns()
   self:refreshMonitorActivityIcon()
   self:refreshOtherBtns()
end

function DesktopController:refreshMonitorActivityIcon()
    local monitorActivityIconInfo = app:sendMsg("RewardModel", "getMonitorActivityIconInfo")
    local funcId = Constant["FUNC_TYPE_REWARD_MONITOR_TRACE"]
    local hasChange = false
    if monitorActivityIconInfo.activityNum and monitorActivityIconInfo.activityNum > 0 then
        local isChange = self.mDesktopModel:addFuncId(funcId,true)
        hasChange = hasChange or isChange
    else
        local isChange = self.mDesktopModel:removeFuncId(funcId)
        hasChange = hasChange or isChange
    end

    if hasChange then
        self:refreshNewFunction()
    end

    app:sendMsg("RewardModel", "updateMonitorActivityIconRedPoint")
end


function DesktopController:refreshRewardBtns()
    local traceList = app:sendMsg("RewardModel", "getTraceList")
    local len = traceList and #traceList or 0

    --首先需要移除旧的icon
    local funcId = 0
    local hasChange = false
    local params = {}
    for i = 1 ,4 do
        funcId = Constant["FUNC_TYPE_REWARD_TRACE"..i]
        if i <= len then
            local trace = traceList[i]
            local p = {
                funcId = funcId,
                icon1Path = Res.gamePlayPath..trace.iconName,
                icon2Path = Res.gamePlayPath..trace.iconName,
            }
            params[#params + 1] = p
            local isChange = self.mDesktopModel:addFuncId(funcId, true, {icon1Path = p.icon1Path,icon2Path = p.icon2Path})
            hasChange = hasChange or isChange
        else
            local isChange = self.mDesktopModel:removeFuncId(funcId)
            hasChange = hasChange or isChange
        end
    end

    if hasChange then
        self:refreshNewFunction()
    end

    for _,param in ipairs(params) do
        self.mDesktop:refreshRewardBtn(param)
    end

    --设置他们的红点
    app:sendMsg("RewardModel", "refreshAllActivityRedPoint")
end

function DesktopController:refreshOtherBtns()
    -- 隐藏每日任务入口
    if UD.setting:getIsHideDailyTaskEntry() then
        local ret = self.mDesktopModel:removeFuncId(Constant.FUNC_TYPE_TASK_DAILY)
        if ret then
            self:refreshNewFunction()
        end
    end
    
    if true then--UD.setting:getIsHideBagRareEntry() then
        local ret = self.mDesktopModel:removeDesktopFuncId(Constant.FUNC_TYPE_PACK_TREASURE)
        if ret then
            self:refreshNewFunction()
        end
    end
end

function DesktopController:addOrDelWorldLock()
    -- 添加世界锁
    local funcId = Constant.FUNC_TYPE_POOR_EXP
    if  UD:getExpPool() > 0 then
        local ret = self.mDesktopModel:addFuncId(funcId, true)
        if ret then
            self:refreshNewFunction({funcId})
        end
    else
        local ret = self.mDesktopModel:removeFuncId(funcId)
        if ret then
            self:refreshNewFunction()
        end
    end
end

function DesktopController:refreshPreviewFunc()
    if app:sendMsg("GameplaypreviewController", "isFuncPreviewOver") then
        self.mDesktopModel:removeFuncId(Constant.FUNC_TYPE_PREVIEW)
        return true
    end
    return false
end

function DesktopController:onEnter()
    self._emHandlers = {}
    self._emHandlers[#self._emHandlers + 1] = EM:on("OnGameConnected",function()
        self:initData()
    end)
    self._emHandlers[#self._emHandlers + 1] = EM:on("onEnterDungeon",function()
        self.mDesktop:refreshTeamGroup()
    end)

    self.playerHandler = UD.player:onChanged(function(name,old,new)
        if name=="level" then
            local openFuncIds = self.mDesktopModel:updateFuncByLev(old, new)
            local hasChange = self:refreshPreviewFunc()
            if #openFuncIds > 0 or hasChange then
                self:refreshNewFunction(openFuncIds)
            else
                self:_refreshGamePlayPreviewIcon()
            end

            -- 按配置插入升级tips，当前等级是否显示的配置在前一级里面（方便策划）
            local lvConf = GD:queryHeroLevelUpByLevel(new-1)
            if lvConf.dropShow == "1" then
                local params = {
                    remindId = Constant.FUNC_TYPE_PLAYER_UP,
                    dataTemp = new
                }
                self:insertFourthTips( params )
            end

            self:addOrDelWorldLock()

            -- 检查是否开启新的英雄之路
            app:sendMsg("TaskController", "checkHasNewRoadOfHero", old, new)
        elseif name == "expPool" then
            self:addOrDelWorldLock()
        end
    end)

    -- 服务器控制功能开发
    self._featureHandler = UD:onChanged("closedFeature", function(funcId, isClose)
        local ret = self.mDesktopModel:updateFuncByServer(funcId, isClose)
        if ret then
            self:refreshNewFunction({funcId})
        end
    end)

    self._taskHandler = UD:onChanged("task", function(tasks, op)
            if op == "update" then
                for k,task in pairs(tasks) do
                    if task:isFinished() then
                        -- 任务完成加系统log
                        if task:isBroadCastSystem() then
                            app:sendMsg("IMModel", "addSystemMsg", "taskCompletetips", task:getName())
                        end
                        if task:isMain() then
                            local hasChange = self:refreshPreviewFunc()
                            local openFuncIds = self.mDesktopModel:updateFuncByTask(task.id)
                            if #openFuncIds > 0 or hasChange then
                                self:refreshNewFunction(openFuncIds)
                            else
                                self:_refreshGamePlayPreviewIcon()
                            end
                        end
                    end
                end
            end
        end)
    
    -- self._mountSoulHandler = UD:onChanged("mountSoul",handler(self, self._updateMountRedPoint))

    self.mDesktop:addEventListener("onOpenFunction", function(event)
        self:openFunction(event.functionId)
    end)

    self.mDesktop:getPlayerInfo():addEventListener("onSwitchOwnerPlayerMenu", function(event)
        local params = {type=Enums.MenuType.head, pos=event.pos}
        app:sendMsg("HeadMenuController", "showView", params)
    end)

    self.mDesktop:getTeamGroup():addEventListener("onSwitchMemberPlayerMenu", function(event)
        app:sendMsg("NewTeamMemberController", "openView")
    end)

    self.mDesktop:getWheel():setControlCallback(function(moveFlag)
        FieldManager:moveControl(moveFlag)
    end)

    self._msdkDataChangeHandler = UD.msdkData:onChanged(handler(self, self._onMsdkDataChange))
    self._msdkFriendUpdateHandler = EM:on("onChannelFriendsUpdate", handler(self, self._onMsdkFriendUpdate))
    self._msdkWakeUpChangeHandler = EM:on("onWakeUpChange", handler(self, self._onMsdkWakeUpUpdate))
    local minimapTemp = self.mDesktop:getMiniMap()
    minimapTemp:setControlCallback(function()
        local mapId = minimapTemp:getData()
        if not mapId then
            print( " --------------->>>>>> 地图Id不存在 " )
            return
        end
        local mapConf = GD:queryMapById( mapId )
        local mapType = tonumber( mapConf.maptype )

        if app:sendMsg("NewActivityDungeonsModel", "isChampionMap") then -- 冠军赛准备场
            print("-------------11")
            if app:sendMsg("PvpModel", "checkMyTeamIsKnockOut") or app:sendMsg("PvpModel", "checkIsChampion") then -- 我的队伍被淘汰 或者 获得了冠军, 直接退出
                app.session:request("pb_throne.C2S_LeaveThroneMap", {})
            else
                local quitTeamDialog = display.newConfirmDialog(L("ThroneQuitTips"), function() -- 确定
                    app.session:request("pb_throne.C2S_LeaveThroneMap", {})
                end)
                UIHandler:addPopDialog( quitTeamDialog )
            end
        elseif UD.csGuildWarData:isCSGuildWarPrepareMap() then -- 跨服 工会战 准备场
            local stage = UD.csGuildWarData:getTodayStage()
            if not UD.csGuildWarData:isMyGuildCanJoin() or stage == Enums.CSGuildWarTodayStage.NotBegin or  
                stage == Enums.CSGuildWarTodayStage.End or UD.csGuildWarData:getHp() == 0 then
                UD.csGuildWarData:C2S_LeaveWorldGuildWarMap()
            else
                local quitTeamDialog = display.newConfirmDialog(L("CSGuildWarQuitTips"), function() -- 确定
                    UD.csGuildWarData:C2S_LeaveWorldGuildWarMap()
                end)
                UIHandler:addPopDialog( quitTeamDialog )
            end
        elseif app:sendMsg("DynastyMapModel", "isDynastyMap") then -- 公会战场
            local str = L("lua_code_text_236") 
            if TeamModel:hasTeam() and not TeamModel:isMyTeam() then -- 有队伍 并且是 队员
                str = L("lua_code_text_443") 
            end
            local quitTeamDialog = display.newConfirmDialog(str, function()
                local holdInfo = GD:getStrongholdInfoByMapId(mapId)
                app.session:request("pb_town.C2S_QuitTownWar", {id = tonumber(holdInfo.districtID), strongholdId = tonumber(holdInfo.ID)})
            end)
            UIHandler:addPopDialog(quitTeamDialog)
        elseif DungeonManager:isCrossDungeon() then -- 跨服匹配副本
            local tips = DungeonManager:isDungeonFinished() and L("lua_code_text_21") or L("CrossServerTips21")
            local quitTeamDialog = display.newConfirmDialog(tips,
                function() -- 确定
                    DungeonManager:leaveDungeonRequest()
                end)
            UIHandler:addPopDialog( quitTeamDialog )
        elseif 1 ~= mapType and 4 ~= mapType and 6 ~= mapType then -- 非主场景、家园、公会？
            if TeamModel:hasTeam() then -- 有队伍？
                if TeamModel:isMyTeam() then -- 我是队长？
                    local str = L("lua_code_text_21")
                    local leaveDungeonDialog = display.newConfirmDialog(str,
                        function() -- 确定
                            if tonumber( mapId ) == tonumber(S("lionHeartHornMapID")) then -- 狮心号角场景？
                                local NewActivityDungeonsModel = app:getInst( "NewActivityDungeonsModel" )
                                if NewActivityDungeonsModel then
                                    NewActivityDungeonsModel:reqLeaveLionHorn()
                                end
                            else
                                if 2 == mapType then
                                    DungeonManager:leaveDungeonRequest()
                                else
                                    app.session:request("pb_map.C2S_BackToLastMap", {})
                                end
                            end
                        end)
                    UIHandler:addPopDialog( leaveDungeonDialog )
                else
                    local str = L("lua_code_text_324")
                    local quitTeamDialog = display.newConfirmDialog(str,
                        function() -- 确定
                            TeamModel:reqQuitTeam()
                        end)
                    UIHandler:addPopDialog( quitTeamDialog )
                end
            else
                local quitTeamDialog = display.newConfirmDialog( L("lua_code_text_21"),
                    function() -- 确定
                        if 2 == mapType then
                            DungeonManager:leaveDungeonRequest()
                        else
                            app.session:request("pb_map.C2S_BackToLastMap", {})
                        end
                    end)
                UIHandler:addPopDialog( quitTeamDialog )
            end
        else
            app:sendMsg("WorldMapController", "openView")
        end
    end)

    -- 队伍更新通知
    app:addCustomEventListener("EVENT_TEAM_UPDATE",function(event)
        self.mDesktop:refreshTeamGroup()
    end,self)

    app:addCustomEventListener("EVENT_REFRESH_PLAYER_HEAD",function(event)
        if event._usedata then
            local uid = event._usedata.uid
            if tonumber(uid) == tonumber(UD:getPlayer().uid) then
                self.mDesktop:getPlayerInfo():refreshPlayerHead()
            end
            self.mDesktop:getTeamGroup():refreshSingelHead(uid)
        end
    end,self)

    app:addCustomEventListener("EVENT_REFRESH_PLAYER",function(event)
        if event._usedata then
            self.mDesktop:refreshPlayerInfo(event._usedata)
        end
    end,self)

    app:addCustomEventListener("EVENT_MAP_SITE",function(event)
        if not event._usedata then return end
        local mapId = event._usedata.mapId
        local mapSiteView = MapSiteView.new(mapId)
        self:addChild(mapSiteView)
    end,self)

    self:addTaskFinishListener()

    app:addCustomEventListener("ESCORT_FINISH_EVENT",function(event)
        if not event._usedata then
            return
        end
        local visible = event._usedata.visible
        self:escortFinishvisibility(visible)
    end,self)

    app:addCustomEventListener("EVENT_GET_ACHIEVEMENT",function(event)
        if not event._usedata then return end
        local achivementConf = GD:getAchievementConfig( event._usedata.achID )
        UIHandler:showThirdLevelTips( { remindId = Constant.FUNC_TYPE_ACHIEVEMENT_GOT, params = achivementConf } )

        AchievementManager.newAch[event._usedata.achID] = true
        UD.badge:setNum(Constant.FUNC_TYPE_ACHIEVEMENT, 1)
    end,self)

    -- 冠军赛 右下角提示
    local pvpModel = app:getInst("PvpModel")
    if pvpModel then
        pvpModel:setChampionNotice()
        pvpModel:setChampionMatchSuccessNotice()
    end

    --
    self._mapChangeHandler = EM:on("onMapChanged",function(eventName, isFirstEnterMap)
        UIHandler:updateMainTaskEffect()
    end)


    self._dungeonSecretInfoChangeHandler =  EM:on(SecretManager.EvtSecretInfoChange,handler(self, self._onDungeonSecretInfoChange))
end

-- function DesktopController:_updateMountRedPoint()
--     local moundModel = app:getInst("MountModel")
--     if moundModel then
--         moundModel:checkMountCanSummon()
--         if self.mDesktop then
--             self.mDesktop:refreshRedPoint({Constant.FUNC_TYPE_MOUNT})
--         end
--     end
-- end

function DesktopController:onExit()
    print("DesktopController:onExit()")
    UD.player:unChanged(self.playerHandler)
    UD:unChanged(self._taskHandler)
    UD:unChanged(self._featureHandler)
    -- UD:unChanged(self._mountSoulHandler)
    UD.msdkData:unChanged(self._msdkDataChangeHandler)

    EM:remove(self._msdkFriendUpdateHandler)
    EM:remove(self._msdkWakeUpChangeHandler)
    
    EM:remove(self._mapChangeHandler)
    EM:remove(self._dungeonSecretInfoChangeHandler)
    for _,handler in ipairs(self._emHandlers) do
        EM:remove(handler)
    end
end

function DesktopController:getDesktop()
    return self.mDesktop
end

function DesktopController:refreshNewFunction(funcIds)
    self:initFunctionByIds()
end

function DesktopController:initFunctionByIds()
    self.mDesktop:initFunctionByIds()
    self.mDesktop:refreshRedPoint()
    self:_refreshGamePlayPreviewIcon()

    self:decideFunctionOpen()
end

function DesktopController:getDesktopUiNode()
    return self.mDesktop:getUiNode()
end

function DesktopController:getDesktopTopScene()
    return self.mDesktop:getTopScene()
end

function DesktopController:show()
    self:setVisible(true)

    if not DungeonManager:isInDungeon() then -- 非副本中?
        if app:getInst( "NewActivityDungeonsModel" ):isLionHornMap() then  -- 在狮心号角场景中
            self.mDesktop:hideLionHornDesktop() -- 隐藏狮心号角场景中部分节点
        elseif app:getInst( "NewActivityDungeonsModel" ):isChampionMap() then -- 在冠军赛准备场中
            self.mDesktop:hideChampionDesktop()
        elseif UD.csGuildWarData:isCSGuildWarPrepareMap() then
            self.mDesktop:hideCSGuildWarDesktop()
        elseif app:getInst("DynastyMapModel"):isDynastyMap() then -- 在公会战准备场中
            self.mDesktop:hideDynastyDesktop()
        else
            self.mDesktop:resetDesktop() -- 重置在上面的场景中被隐藏的节点
        end
    end

    self:checkGuide()
end

-- 设置主界面右下角提示visible
function DesktopController:setDesktopTipVisible(b)
    local fourthTips = self.mDesktop:getFourthTips()
    fourthTips:setVisible(b)
    if b then
        fourthTips:checkGuide()
    end
end

-- 检查是否触发了引导，快捷装备引导和右下角提示引导也算在desktop里面
-- 三种引导按获得顺序依次引导
function DesktopController:checkGuide()
    -- 主界面引导在下列条件时不触发 1.有其他ui  2.非主城地图
    if UIHandler:isHaveUI() then return end
    -- if not MapManager:isInNormalMap() then return end

    local params = {
        scene = Constant.FUNC_TYPE_DESKTOP,
        sceneSelf = self,
        getFunc = self.getGuideNodeFunc,
        nextFunc = self.checkGuide
    }
    EM:notify("checkGuide", params)

    self.mDesktop:getFourthTips():checkGuide()

    app:sendMsg("UIController", "quickViewCheckGuide")
end

-- 获取引导node
function DesktopController:getGuideNodeFunc(id, funcId)
    -- print("DesktopController:getGuideNodeFunc", id, funcId)

    -- 1. DesktopController不可见，不引导
    if not self:isVisible() then return end

    local desktop = self.mDesktop
    -- 2. desktop不可见，或者fade中，不引导
    if not desktop:isVisible() then return end

    -- 3. 有除Desktop之外的UI，不引导
    if UIHandler:isHaveUI() then return end

    if funcId then
        local config = GD:queryFeatureOnById(funcId)
        local pos = config and tonumber(config.pos)
        if pos then
            local canGet = false
            if pos <= 16 then
                -- 1. 如果是右下角的按钮，因为有切换和动画，需要判断是否动画结束和可见
                -- pos <= 16 为右下角按钮
                if not desktop:isBottomActionPlaying() then
                    if desktop:isBottomOpen() then
                        -- open=true, pos <= 8 可见
                        canGet = pos <= 8
                        if not canGet then
                            desktop:closeBottomAction()
                        end
                    else
                        -- open=false, pos > 8 可见
                        canGet = pos > 8
                        if not canGet then
                            desktop:openBottomAction()
                        end
                    end
                end
            elseif pos >= 21 and pos <= 35 then
                -- 2. 如果是上方按钮，因为有展开和收拢状态，需要判断状态
                if not desktop:isInTopSwitch() then
                    if desktop:isTopOpen() then
                        canGet = true
                    else
                        desktop:switchTop(true)
                    end
                end
            elseif pos >= 40 and pos <= 46 then
                -- 右方按钮不可见时不能触发
                canGet = desktop:isRightNodeVisible()

                -- 补丁，试图触发引导而按钮不可见，主要用在副本中触发支线任务的提示
                if not canGet then
                    app:sendMsg("GuideModel", "cancelSideTaskGuide")
                    display.pushToast(L("Errguide1"))
                end
            else
                canGet = true
            end

            if canGet then
                local btn = desktop:getBtnByFuncId(funcId)
                return btn
            else
                return nil
            end
        end
    end

    if id == 101 then
        -- 移动教学
        local wheelRoot = desktop:getWheel():getUIRoot()
        return wheelRoot
    elseif id == 104 then
        -- 任务寻路提示
        return self.mTaskTrackController:getMainNode()
    elseif id == 390 then
        return self.mTaskTrackController:getMainNode()
    end
end

function DesktopController:getTaskTrackController()
    return self.mTaskTrackController
end

function DesktopController:decideFunctionOpen()
    if UIHandler:isFunctionOpen(Constant.FUNC_TYPE_CHAT) then
        UIHandler:showChatUI()
    end

    if self.mTaskTrackController then
        self.mTaskTrackController:setVisible(UIHandler:isFunctionOpen(Constant.FUNC_TYPE_TASK_TRACK))
    end

    self.mDesktop:decideFunctionOpen()
end

function DesktopController:addTaskFinishListener()
    local function excute(task)
        if not task then return end
        local taskConfig = task:getConfig()
        if taskConfig then
            if tonumber(taskConfig.questFinish) == 1 then
                if StoryManager:isEnterStoryMode() then
                    self.mDesktopModel:saveTaskFinish(taskConfig)
                end
            end
        end
    end

    local function sendTaskMessage(task)
        if not task then return end
        local taskConfig = task:getConfig()
        if taskConfig then
            local questMsg = tonumber(taskConfig.questMessage)
            if questMsg == 1 then
                if task:isSide() and task:isTaken() then
                    if task:getDefaultDone() == 0 and task:getDefaultTotal() >= 0 then
                        app:popMessage("pick_up_sidequests", {L(taskConfig.name)})
                    end
                end
            elseif questMsg == 2 then
                if task:isDaily() and task:isTaken() then
                    if task:getDefaultDone() == 0 and task:getDefaultTotal() >= 0 then
                        app:popMessage("pick_up_daily", {L(taskConfig.name)})
                    end
                end
            elseif questMsg == 3 then
                if task:isFinished() then
                    app:popMessage("task_progress_update")
                end
            elseif questMsg == 4 then

            end
        end
    end

    app:addCustomEventListener("EVENT_TASK_TRACK",function(event)
        if not event._usedata then return end

        local task = event._usedata.task
        if task then
            if task:isFinished() or task:isRewarded() then
                if task:isMain() or task:isSide() or task:isDaily() then
                    excute(task)
                end
            end
            sendTaskMessage(task)
        end

    end,self)

    app:addCustomEventListener("EVENT_TASK_FINISH_STORY",function(event)
        self:playTaskFinishAfterStory()
        -- 剧情播放完显示战备界面
        TeamModel:showTeamReadyUIOnStoryOver()
    end,self)
end

function DesktopController:playTaskFinishAfterStory()
    local taskFinish = self.mDesktopModel:getTaskFinish()
    if taskFinish then
        self.mDesktopModel:clearTaskFinish()
    end
end

function DesktopController:escortWarningVisibility(visible)
    if visible then
        if not self.mEscortWarning then
            self.mEscortWarning = EscortWarning.new(self)
            self:addChild(self.mEscortWarning)
            self.mEscortWarningId = AM.playSoundById(1015)
        end
    else
        self:removeChild(self.mEscortWarning)
        self.mEscortWarning = nil
        if self.mEscortWarningId then
            AM.stop(self.mEscortWarningId)
            self.mEscortWarningId = nil
        end
    end
end


function DesktopController:escortFinishvisibility(visible)
    if visible then
        if not self.mEscortFinish then
            self.mEscortFinish = EscortFinish.new()
            self:addChild(self.mEscortFinish)
        end
    else
        self:removeChild(self.mEscortFinish)
        self.mEscortFinish = nil
    end
end

function DesktopController:showTaskTrack()
    if not self.mTaskTrackController then
        self.mTaskTrackController = TaskTrackController.new(self.mDesktop:getTrackRoot())
        self.mDesktop:addChild(self.mTaskTrackController)
    else
        self.mTaskTrackController:setVisible(true)
    end
end

function DesktopController:hideTaskTrack()
    if self.mTaskTrackController then
        self.mTaskTrackController:setVisible(false)
    end
end

function DesktopController:openFunction(functionId)
    if BattleManager:isBattle() or StoryManager:isEnterStoryMode() then -- 战斗、剧情中
        return
    end

    -- local badgeNum = 0
    -- -- 使用真实的红点标记（策划倾向于都是真实的红点标记）
    -- if functionId == Constant.FUNC_TYPE_TASK or
    --     functionId == Constant.FUNC_TYPE_CJ or
    --     functionId == Constant.FUNC_TYPE_MOUNT or
    --     functionId == Constant.FUNC_TYPE_MAIL or
    --     functionId == Constant.FUNC_TYPE_SHOP or
    --     functionId == Constant.FUNC_TYPE_JEWEL or
    --     functionId == Constant.FUNC_TYPE_CALENDAR
    --     then

    --     badgeNum = UD.badge:getNum(functionId)
    -- else
    --     -- 使用默认的红点标记，按钮点击之后就清理掉
    -- end

    -- if UD.badge:setNum(functionId, badgeNum) then
    --     UD.dirty = true
    -- end
    -- UD.redPoint:setClicked(functionId)

    UIHandler:handleMessage({id = functionId,mode = "open"})
end

-- 更新功能预告Icon
function DesktopController:_refreshGamePlayPreviewIcon()
    if not self.mDesktopModel:isFuncOpen(Constant.FUNC_TYPE_PREVIEW) then return end

    if self.mDesktop then
        local controllerTemp = app:getInst( "GameplaypreviewController" )
        local iconPath = controllerTemp:getDesktopIconPath()
        if "" ~= iconPath then
            self.mDesktop:setGamePlayPreviewIcon( iconPath )
        end
    end
end

-- 插入通知
function DesktopController:insertFourthTips( params )
    scheduler.newCron(function()
        local fourthTipsTemp = self.mDesktop:getFourthTips()
        fourthTipsTemp:insertData( params )
    end, 1)
end
-- 移除通知
function DesktopController:removeFourthTips( params )
    local fourthTipsTemp = self.mDesktop:getFourthTips()
    fourthTipsTemp:removeData( params )
end
function DesktopController:removeFourthTipsByType( t )
    local fourthTipsTemp = self.mDesktop:getFourthTips()
    fourthTipsTemp:removeByType( t )
end


function DesktopController:_onMsdkDataChange()
    if self.mDesktop then
        self.mDesktop:refreshMsdk()
    end
end

function DesktopController:_onMsdkFriendUpdate()
    if self.mDesktop then
        self.mDesktop:refreshMsdkHead()
    end
end


function DesktopController:_onMsdkWakeUpUpdate()
    if app.session:isLogined() then
        UD.msdkData:requestMsdkBusiness()
    end
end

-- 广告弹窗节点
function DesktopController:setDesktopAdvertNodeVisible(b)
    local advertNode = self.mDesktop:getAdvertNode()
    if advertNode then
        advertNode:setVisible(b)
    end
end

function DesktopController:_onDungeonSecretInfoChange()
    if self.mDesktop then
        self.mDesktop:refreshSecretInfo()
    end
end




return DesktopController
